//
//  Condition.hxx
//  Simulation
//
//  Created by Christopher Kemsley on 2/28/12.
//  Copyright (c) 2012 iAppolopolis. All rights reserved.
//





template <typename TargetType,typename ContextType>
ObjectCondition<TargetType,ContextType> :: ObjectCondition		( TargetType const * inTarget , CallbackMethod inMethod , ContextType const & inContext )
:	Condition	()
,	mTarget		( inTarget )
,	mContext	( inContext )
,	mMethod		( inMethod )
	{
	}


template <typename TargetType,typename ContextType>
bool		ObjectCondition<TargetType,ContextType> :: isTrue ()
	{
	return (mTarget->*mMethod) ( mContext ) ;
	}


template <typename TargetType,typename ContextType>
Condition*	ObjectCondition<TargetType,ContextType> :: create	( TargetType const * inTarget , CallbackMethod inMethod , ContextType const & inContext )
	{
	if ( inTarget==0 )
		throw Exception ( "ObjectCondition" , "Target was nil in constructor" , __FILE__,__LINE__ ) ;
	if ( inMethod==0 )
		throw Exception ( "ObjectCondition" , "Method was nil in constructor" , __FILE__,__LINE__ ) ;
	return new ObjectCondition<TargetType,ContextType> ( inTarget , inMethod , inContext ) ;
	}


template <typename TargetType,typename ContextType>
Condition*	ObjectCondition<TargetType,ContextType> :: condition	( TargetType const * inTarget , CallbackMethod inMethod , ContextType const & inContext )
	{
	Condition * c = create ( inTarget , inMethod , inContext ) ;
	c -> autorelease () ;
	return c ;
	}
